package cn.tedu.charging.cost.repo;

import cn.tedu.charging.common.pojo.po.ChargingCostRulePO;
import cn.tedu.charging.cost.mapper.CostRuleMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Date;

@Repository
public class CostRepo {
    @Autowired
    private CostRuleMapper costRuleMapper;

    public ChargingCostRulePO getCostRule(Integer stationId, Date date) {
        // where station_id = ? and start_time <= ? and end_time >= ?
        // 1. 通过Date.now()获取当前小时数
        int hour = date.getHours();
        QueryWrapper<ChargingCostRulePO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("station_id", stationId).
                le("start_time", hour).
                ge("end_time", hour);
        return costRuleMapper.selectOne(queryWrapper);
    }
}
